package com.zang.blogz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zang.blogz.entity.WebsiteConfig;
import com.zang.blogz.mapper.WebsiteConfigMapper;
import com.zang.blogz.model.output.WebsiteConfigVO;
import com.zang.blogz.service.ArticleService;
import com.zang.blogz.service.CategoryService;
import com.zang.blogz.service.TagService;
import com.zang.blogz.service.WebsiteConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 朵橙i
 * @since 2022-06-21
 */
@Service
public class WebsiteConfigServiceImpl extends ServiceImpl<WebsiteConfigMapper, WebsiteConfig> implements WebsiteConfigService {


    @Autowired
    private ArticleService articleService;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private TagService tagService;

    @Override
    public WebsiteConfigVO getUserInfo() {

        WebsiteConfig config = list().stream().findFirst().get();

        WebsiteConfigVO websiteConfigVo = BeanUtil.copyProperties(config, WebsiteConfigVO.class);
        websiteConfigVo
                .setArticleCount(articleService.count())
                .setTypeCount(categoryService.count())
                .setTagCount(tagService.count())
                .setViewCount(config.getViewCount());
        ;

        return websiteConfigVo;
    }


}
